import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-04-11
 * Time: 18:42
 */
public class test0 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s1=scanner.next();
        String s2 =scanner.next();
        String tmp=" ";
        if(s1.length()>s2.length()){
            tmp=s1;
            s1=s2;
            s2=tmp;
        }
        int left =0;
        int right = left+1;
        String str =" ";
        String str1=" ";
        while (right<=s1.length()){

            str=s1.substring(left,right);
            if ( s2.contains(str)) {
               right++;
               tmp=str;
              if(tmp.length()>str1.length()){
                  str1=tmp;
              }
            }else {
                left++;
                right=left+1;
            }

        }
        System.out.println(tmp);
    }
}
